// 文本说明

import React, {useEffect, useState} from 'react';
import {Input, Spin, Card} from 'antd';
import {queryValues} from '~/service/refundReport';
import './common.styl';

const {TextArea} = Input;

const DataText = props => {
    const {dId, unitId} = props;
    const [loading, setLoading] = useState(false);
    const [content, setContent] = useState();

    const getData = () => {
        const dashBoard = [
            {
                dashBoardName: dId,
                dashBoardId: dId
            }
        ];
        const param = {
            dimensionAndValues: [],
            dashBoardList: dashBoard,
            drilingList: []
        };
        setLoading(true);
        queryValues(param)
            .then(res => {
                const cardDetail = res?.data[dId] ?? null;
                if (cardDetail) {
                    const {textContent} = cardDetail[`${unitId}`];
                    setContent(textContent);
                }
            })
            .finally(() => {
                setLoading(false);
            });
    };

    useEffect(() => {
        getData();
    }, [dId, unitId]);

    return (
        <div style={{height: '100%', marginBottom: 8}} className="common-text-container">
            <Spin spinning={loading}>
                <TextArea
                    className="common-text-area"
                    value={content}
                    readOnly
                    bordered={false}
                    style={{height: 108}}
                />
            </Spin>
        </div>
    );
};

export default DataText;
